const { createAvatar } = require("../services/avatarService");
const { saveAvatar } = require("../services/UserService");

class AvatatController {

  // 创建用户头像
  async createAvatar (ctx) {
    const { filename, type, size } = ctx.request.files.file;
    const {userId} = ctx.request.body;
    const result = await createAvatar({filename, mimetype: type, size, userid: userId})
    // 将头像的url保存到users表中
    const avatarUrl = `/${filename}`
    await saveAvatar(avatarUrl, userId)
    ctx.body = result
  }
}

module.exports = new AvatatController()